package ezXpns.analysis.aggregators;

import java.util.HashMap;
import java.util.UUID;

import org.apache.commons.lang3.tuple.Pair;


//@author A0088827L
import ezXpns.analysis.Aggregator;
/**
 * 
 * @author A0086931X
 *
 */
public class TagSum implements Aggregator<Pair<String, Float>, HashMap<String, Float>> {
	public TagSum() {
		tagMap = new HashMap<String, Float>();
	}

	@Override
	public void addEntry(UUID id, Pair<String, Float> item) {
		
		String[] tagArray = item.getLeft().split(",");

		for (String s : tagArray) {
			if (tagMap.containsKey(s)){
				tagMap.put(s, item.getRight() + tagMap.get(s));
			}
			else{
				tagMap.put(s, item.getRight());
			}
		}
	}

	@Override
	public HashMap<String, Float> getResult() {
		return tagMap;
	}
	
	@Override
	public void removeEntry(UUID id, Pair<String, Float> item) {
		return;		
	}
	
	private HashMap<String, Float> tagMap;
}